<?php

namespace App\Models;

use App\Http\Controllers\PCHController;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Redis;

/**
 * App\Models\rebate
 *
 * @mixin \Eloquent
 * @property int $id
 * @property float $BNF_Lv1 一级分销比例
 * @property float $BNF_Lv2 一级分销比例
 * @property float $BNF_Lv3 一级分销比例
 * @property float $BNF_Lv4 一级分销比例
 * @property int $update_at 修改时间
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\rebate whereBNFLv1($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\rebate whereBNFLv2($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\rebate whereBNFLv3($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\rebate whereBNFLv4($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\rebate whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\rebate whereUpdateAt($value)
 * @property \Carbon\Carbon $updated_at 修改时间
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\rebate whereUpdatedAt($value)
 */
class rebate extends Model
{
    protected $table = 'rebate_rate';

    public static function getRateList()
    {
        $data = self::first();
        if (!empty($data)){
            $data = $data->toArray();
            $key  = PCHController::getRateListKey();
            Redis::HMSET($key,$data);
        }else{
            return [];
        }
        return $data;
    }

    public static function  modifyRate($key,$rate)
    {
        $flag = self::where('id','=',1)->update([$key=>$rate]);
        return $flag;
    }


}
